package com.aldd.controller;

import com.aldd.entity.Book;
import com.aldd.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping(produces = "application/json;charset=utf-8")
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("selectAllBook")
    public List<Book> selectAllBook() {
        return bookService.selectAllBook();
    }
    @RequestMapping("selectBookById")
    public Book selectBookById(int id) {
        return bookService.selectBookById(id);
    }
    @RequestMapping("deleteBookById")
    public String deleteBookById(int id) {
        return bookService.deleteBookById(id) ? "成功" : "失败";
    }
    @RequestMapping("insertBook")
    public String insertBook(@RequestBody Book book) {
        return bookService.insertBook(book) ? "成功" : "失败";
    }
    @RequestMapping("updateBook")
    public String updateBook(@RequestBody Book book) {
        return bookService.updateBook(book) ? "成功" : "失败";
    }
    @RequestMapping("selectBookByBookName")
    public List<Book> selectBookByBookName(String bookName) {
        return bookService.selectBookByBookName(bookName);
    }
}
